package com.zcc.makingfriend.controller;

import com.zcc.makingfriend.dao.WebLogin;
import com.zcc.makingfriend.service.LoginService;
import com.zcc.makingfriend.service.WebLoginService;
import com.zcc.makingfriend.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 微信登录
 * @author zcc
 */
@Api(tags = "登录")
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    LoginService loginService;

    @Autowired
    WebLoginService webLoginService;

    @ApiOperation("微信登录")
    @GetMapping("/wxLogin/{code}")
    public Result wxLogin(@PathVariable String code){
        Result result = loginService.wxLogin(code);
        return result;
    }

    @ApiOperation("管理员登录")
    @PostMapping("/webLogin")
    public Result webLogin(@RequestBody WebLogin webLogin){
        String login = webLoginService.login(webLogin);
        if (login.equals("登录成功")) {
            return Result.success(webLogin.toString());
        }
        return Result.fail(login);
    }
}
